//
//  HEGoodsDetailsAreaCell.m
//  HealthElderly
//
//  Created by LOOK on 2020/10/24.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEGoodsDetailsAreaCell.h"

@interface HEGoodsDetailsAreaCell()

@property(nonatomic, strong) UILabel *nameLb;
@property(nonatomic, strong) UIButton *conactBtn;
@property(nonatomic, strong) UILabel *addressLb;
@property(nonatomic, strong) UILabel *areaLb;

@end

@implementation HEGoodsDetailsAreaCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
    // 机构名称
    _nameLb = [UILabel new];
    _nameLb.text = @"--";
    _nameLb.font = DYFont(16);
    _nameLb.numberOfLines = 0;
    [self.contentView addSubview:_nameLb];
    
    // 联系电话
    _conactBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _conactBtn.adjustsImageWhenHighlighted = NO;
    _conactBtn.titleLabel.font = DYFont(16);
    [_conactBtn setImage:IMAGE_NAMED(@"call_main") forState:UIControlStateNormal];
    [_conactBtn setTitle:@"电话咨询" forState:UIControlStateNormal];
    [_conactBtn setTitleColor:KHexColor(@"#3E8BF8") forState:UIControlStateNormal];
    [self.contentView addSubview:_conactBtn];
    [_conactBtn addTarget:self action:@selector(callPhone) forControlEvents:UIControlEventTouchUpInside];;
    
    // 服务地址
    UIImageView *areaIcon = [UIImageView new];
    areaIcon.contentMode = UIViewContentModeScaleAspectFill;
    areaIcon.image = IMAGE_NAMED(@"send_address");
    [self.contentView addSubview:areaIcon];
    
    _addressLb = [UILabel new];
    _addressLb.font = DYFont(14);
    _addressLb.numberOfLines = 0;
    _addressLb.textColor = KHexColor(@"#AAAAAA");
    _addressLb.text = @"--";
    [self.contentView addSubview:_addressLb];
    
    // line
    UIView *line = [UIView new];
    line.backgroundColor = KHexColor(@"#FAFAFA");
    [self.contentView addSubview:line];

    // 服务区域
    UILabel *areaTitlLb = [UILabel new];
    areaTitlLb.font = DYFont(16);
    areaTitlLb.text = @"服务区域：";
    [self.contentView addSubview:areaTitlLb];
    
    _areaLb = [UILabel new];
    _areaLb.font = DYFont(14);
    _areaLb.text = @"服务区域：";
    _areaLb.numberOfLines = 0;
    _areaLb.textColor = KHexColor(@"#AAAAAA");
    [self.contentView addSubview:_areaLb];
    
    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(_conactBtn.mas_left).mas_offset(-10);
    }];
    
    [_conactBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.contentView).mas_offset(15);
       make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [areaIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLb.mas_bottom).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.width.mas_offset(13);
        make.height.mas_offset(16);
    }];

    [_addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(_nameLb.mas_bottom).mas_offset(10);
       make.left.equalTo(areaIcon.mas_right).mas_offset(5);
       make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_addressLb.mas_bottom).mas_offset(10);
        make.left.equalTo(areaIcon.mas_right).mas_offset(15);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-15);
        make.height.mas_offset(1);
    }];
    
    [areaTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(line.mas_bottom).mas_offset(10);
         make.left.equalTo(self.contentView).mas_offset(15);
    }];
    
    [areaTitlLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_areaLb mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(line.mas_bottom).mas_offset(10);
       make.left.equalTo(areaTitlLb.mas_right).mas_offset(5);
       make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {

    _nameLb.text = formModel.storeModel.name;
    _addressLb.text = nullToDef(formModel.storeModel.addressDetail);
    _areaLb.text = [DYTools isBlankString:formModel.goodsModel.areaLimitName] ? @"不限": formModel.goodsModel.areaLimitName;
}

- (void)callPhone {
    [DYTools callPhone:self.formModel.storeModel.servicePhone];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
